<%@ page contentType="text/html; charset=UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@page import="DAO.ControlDB"%>
<%@page import="Entity.Contact"%>
<%@page import="java.util.ArrayList"%>
<!DOCTYPE html>
<html>
    <head>
        <title>List Contacts</title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <link href="stylelist.css" rel="stylesheet" type="text/css"/>
        <script type="text/javascript">
        function popupwindow(url, title, w, h) {
                var left = (screen.width/2)-(w/2);
                var top = (screen.height/2)-(h/2);
                var w=window.open(url, title, 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width='+w+', height='+h+', top='+top+', left='+left);
                document.form[0].typeofbusiness.value="waiting...";
               
        } 
        
        function getselect(){
		    var radios = document.getElementsByName("select");
		    for (var i = 0; i < radios.length; i++) {       
		        if (radios[i].checked) {
		            return radios[i].value;
		        }
		    }	   
	}
     function returnvalue(){
    	 selectval=getselect();
    	 //alert(selectval);
    	 firstname=document.getElementById(selectval).options[0].value;
    	 //alert(firstname);
    	 window.opener.Lookup.contact.value=firstname;
    	 self.close();
     }
     function returnnone(){
    	 window.opener.Lookup.contact.value=''; 
    	 self.close();
     }
        </script>
        
    </head>
    <body>
        <div id="header">
        </div>
        <div id="content">
           <div >
           <b> Search contact</b>
           
           </div>
            <div id="contentbody">
                <s:form action="search" method="post">
			<table id="search">
				<tr>
					<th>FirstName:</th>
					<td><input type="text" name="firstname" id="firstname" value='<s:property value="firstname"/>' ></td>
					<th>Surname:</th>
					<td><input type="text" name="surname" id="surname" value='<s:property value="surname"/>' ></td>
				</tr>
			</table>
			
			<div id="top">
				<s:submit value="Search Contact" cssStyle="button" />
				<input value="None" type="button" onclick="returnnone()">
				<input type="button" value="Clear" onclick="document.getElementById('surname').value='';document.getElementById('firstname').value='';" >
				<s:submit value="Create" action="add" cssStyle="button" onclick="popupwindow('AddContacts.jsp', 'dsadssa', 650, 600);"/>
			</div>
			<div id="page">
                  <s:submit type="image" name="previous" src="Previous.PNG" width="16px" height="16px" action="previous"/>
                    <input name="pagenumber" type="text" size="3" value='<s:property value="pagenumber"/>'>/<s:property value="totalpage" /> 
                     <s:submit type="image" name="next" src="next.png" width="16px" height="16px" action="next"/>
                    
                </div>
                 <div id="includeinactive">
                    <span>
                       <s:checkbox name="isactive" value="isactive" /><a> Include in-active contacts?</a>
                    </span>
                </div>
		</s:form>
                </div>
                <br>
                <br>
                <br>
                <div id="includeinactive">
                    <span>
                    </span>
                </div>
                <div id="middle">
                    <s:form action= "select"  method="post">
                    
                        <table id="tablecontent">
                            <tr>
                           
                                <th></th>
                                <th>Contact Name</th>
                                <th>Mobile Phone</th>
                                <th>Email</th>
                                <th>Contact Type</th>
                                <th>Is Active?</th>
                            </tr>
                               <s:iterator value="listContact" status="status">
                            <tr>
                                <td><input type="radio" id="select" name="select" value='<s:property value="id"/>' ></td>
                                <td><s:property value="firstName"/> <s:property value="surName"/></td>
                                <td><s:property value="mobilePhone"/></td>
                                <td><s:property value="emailAddress"/></td>
                                <td><s:property value="contactType"/></td>
                                <td><s:property value="isActive"/></td>
                                <td>
			          		        <select id='<s:property value="id"/>' >
				             		      <option value='<s:property value="surName"/>'></option>
			                  	     </select>
								</td>
                            </tr>
                              </s:iterator>
                            
                        </table>
			  <br>
                        <div id="bottom">
                        
                    <input type="button" value="Select" onclick="returnvalue()">
                    <s:submit name="edit" value="Edit" action="edit" cssStyle="button"/>
                     <s:submit name="close" value="Close" cssStyle="button" onclick="window.close()"/>
                </div>
                
                
                    </s:form>    
                </div>
                
             
            </div>
     
        <div id="footer">

        </div>
    </body>
</html>
